<!DOCTYPE html>
<p class="ui-widget ui-widget-content" style="padding-left: 1em;">	
	<span>班级：</span>
	<select id="bjSel" onchange="selChange()">
		<option value="" style="display: none;"></option>
		<option th:each="bj : ${classes}" th:value="${bj.id}" th:text="${bj.name}">1班</option>
	</select>
	<span>课程：</span>
	<select id="kcSel" onchange="selChange()">
		<option value="" style="display: none;"></option>
		<option data-th-each="kc : ${courses}" data-th-value=${kc.id} data-th-text=${kc.name}>课程1</option>
	</select>
	<button id="btn" type="button" onclick="selectByBjIdAndkcId()" disabled="disabled">查询</button>
</p>
<table id="list2"></table>
<div id="pager2"></div>

<script type="text/javascript">
var lastrow;
var lastcell;
var options={
		url : 'grade/list',
		caption : '按班级录入成绩',
		//width: '100%',
		editurl: 'grade/edit',
		autowidth: true,
		cellEdit: true,
		cellurl:'grade/celledit',
	    beforeEditCell: function (rowid, cellname, v, iRow, iCol) {
	          lastrow = iRow;  //给全局变量赋值
	          lastcell = iCol;
	    },
		height : 500,
		hidegrid: false,
		datatype : 'json',
		mtype : 'post',
		rowNum : 10,
		postData: {classId:0},
		rowList : [10,20,50],
		prmNames: {search:"search"},
		sortname : 'id',
		viewrecords : true,
		pager : '#pager2',
		jsonReader : { 
			 repeatitems: false,
			 id : 'id'
		},
		colModel:[
			{label:'id',name:'id',index:'id',align:'center',sortable:true,width:50,sorttype:'int',search:false,hidden:true}, 
			/* {label:'班级',name:'tbClass.id',index:'tbClass.id',hidden:true,align:'center',sortable:true,width:50,sorttype:'int',search:false}, */ 
			{label:'学号',name:'stu.username',index:'stu.username',align:'center',sortable:true,width:100,sorttype:'text',editable:false},
			{label:'姓名',name:'stu.name',index:'stu.name',align:'center',sortable:true,width:100,sorttype:'text',editable:false}, 
			{label:'成绩',name:'grade',index:'grade',align:'center',sortable:true,width:80,editable:true,editrules:{integer:true},sorttype:'int'}
		]
	}
	$(function(){
		$('#list2').jqGrid(options);
		/* $("#list2").jqGrid('navGrid','#pager2',{edit:true,add:true,del:true},{
			left:200,
			top:50,
			beforeSubmit: function(postdata,formid){
				postdata['tbClass.id']=$('#bjSel').val();
				return [true,'OK!'];
			},
			closeAfterEdit:true,
			closeOnEscape:true,
			savekey:[true,13]
		},{
			left:200,
			top:50,
			beforeSubmit: function(postdata,formid){
				postdata.id='',
				postdata['tbClass.id']=$('#bjSel').val();
				return [true,'OK!'];
			},
			closeAfterAdd:true,
			closeOnEscape:true,
			savekey:[true,13]
		},{
			left:200,
			top:50,
			closeOnEscape:true
			
		},{
			left:200,
			top:50,
			closeAfterSearch:true,
			closeAftreReset:true,
			closeOnEscape:true,
			multipleSearch:true
		});*/
	}); 
	
	function selChange(){
		 var bjId=$('#bjSel').val();
		var kcId=$('#kcSel').val();
		if(bjId!==''&&kcId!==''){
			$('#btn').attr('disabled',false);
		}else{
			$('#btn').attr('disabled',true);
		} 
		/* if(lastrow&&lastcell){
			console.info("1");
			$('#list2').jqGrid("saveCell", lastrow, lastcell);  //当前单元格退出编辑模式
			lastrow=null;
			lastcell=null;
			selChange();
		}
		var bjId=$('#bjSel').val();
		var kcId=$('#kcSel').val();
		if(bjId&&kcId){
			var postdata={classId:bjId,courseId:kcId};
			options.postData=postdata;
			$("#list2").setGridParam(options).trigger("reloadGrid");
			console.info("2");
		} */

	}
	
	function selectByBjIdAndkcId(){
		if(lastrow&&lastcell){
			$('#list2').jqGrid("saveCell", lastrow, lastcell);  //当前单元格退出编辑模式
			lastrow=null;
			lastcell=null;
			selectByBjIdAndkcId();
			return;
		}
		
		
		var bjId=$('#bjSel').val();
		var kcId=$('#kcSel').val();
		//alert(2);
		var postdata={classId:bjId,courseId:kcId};
		options.postData=postdata;
		$("#list2").jqGrid('clearGridData');
		$("#list2").setGridParam(options).trigger("reloadGrid");
	}
</script>
